package com.manage.system.web.controller;

import com.manage.common.core.result.JsonResult;
import com.manage.common.core.valid.AddGroup;
import com.manage.common.core.valid.UpdateGroup;
import com.manage.common.log.annotation.OperateLog;
import com.manage.common.log.enums.BusinessType;
import com.manage.system.api.request.dept.DeptAddOrEditParam;
import com.manage.system.api.request.dept.DeptQueryParam;
import com.manage.system.api.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangqing
 * @description 部门控制层
 * @date 2021/4/26 8:00 下午
 */
@RestController
@RequestMapping("/dept")
@AllArgsConstructor
@Api(tags = "SysDeptController", value = "部门控制层")
public class SysDeptController {

    private final ISysDeptService sysDeptService;

    @ApiOperation("获取所有部门信息")
    @PostMapping("/findDeptList")
    public JsonResult findDeptList(@RequestBody DeptQueryParam deptQueryParam){
        return sysDeptService.findDeptList(deptQueryParam);
    }

    @ApiOperation("获取所有部门信息(树形结构)")
    @GetMapping("/findAllDeptTree")
    public JsonResult findAllDeptTree(){
        return sysDeptService.findAllDeptTree();
    }

    @ApiOperation("添加部门")
    @PostMapping("/addDept")
    @OperateLog(module ="部门管理",title = "添加部门", businessType = BusinessType.INSERT)
    public JsonResult addDept(@Validated({AddGroup.class}) @RequestBody DeptAddOrEditParam deptAddOrEditParam){
        return sysDeptService.addDept(deptAddOrEditParam);
    }

    @ApiOperation("删除指定部门")
    @DeleteMapping("/delDeptById/{deptId}")
    @OperateLog(module ="部门管理",title = "根据部门ID删除部门", businessType = BusinessType.DELETE)
    public JsonResult delDeptById(@PathVariable Long deptId){
        return sysDeptService.delDeptById(deptId);
    }

    @ApiOperation("编辑部门")
    @PutMapping("/editDept")
    @OperateLog(module ="部门管理",title = "编辑部门", businessType = BusinessType.UPDATE)
    public JsonResult editDept(@Validated({UpdateGroup.class}) @RequestBody DeptAddOrEditParam deptAddOrEditParam){
        return sysDeptService.editDept(deptAddOrEditParam);
    }
}
